package com.isoftstone.guodian.purExecution.control;

import com.isoftstone.guodian.demo.service.TFultbpurchasingapplyService;
import com.isoftstone.guodian.entity.TFultbpurchasingapplyEntity;
import com.isoftstone.guodian.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ExecuteControl {

    @Autowired
    private TFultbpurchasingapplyService tFultbpurchasingapplyService;

    @RequestMapping("execute")
    public String execute(){//通过参数接受页面请求数据，参数变量名与前台标签name属性名一样即可
        return "/demo/execute.jsp";
    }

    @RequestMapping("dantichaxun")
    public String chaxun(String name, String radio, Model model, Integer pageNow){
        TFultbpurchasingapplyEntity tFultbpurchasingapplyEntity=new TFultbpurchasingapplyEntity();
        try {
            PageUtils page = new PageUtils();
            StringBuffer stringBuffer=new StringBuffer();
            if (pageNow == null) {
                pageNow = 1;
            }
            if(pageNow<=0){
                pageNow=1;
            }
            if(radio!=null){
                if(radio.equals("1")){
                }else if(radio.equals("2")){
                    tFultbpurchasingapplyEntity.setExecutestate("已下达");
                    stringBuffer.append(" and executestate ='"+tFultbpurchasingapplyEntity.getExecutestate()+"'");
                }else if(radio.equals("3")){
                    tFultbpurchasingapplyEntity.setExecutestate("已提交");
                    stringBuffer.append(" and executestate ='"+tFultbpurchasingapplyEntity.getExecutestate()+"'");
                }else if(radio.equals("4")){
                    tFultbpurchasingapplyEntity.setExecutestate("已发布");
                    stringBuffer.append(" and executestate ='"+tFultbpurchasingapplyEntity.getExecutestate()+"'");
                }else if(radio.equals("5")){
                    tFultbpurchasingapplyEntity.setExecutestate("已作废");
                    stringBuffer.append(" and executestate ='"+tFultbpurchasingapplyEntity.getExecutestate()+"'");
                }else if(radio.equals("6")){
                    tFultbpurchasingapplyEntity.setExecutestate("已驳回");
                    stringBuffer.append(" and executestate ='"+tFultbpurchasingapplyEntity.getExecutestate()+"'");
                }
            }
            if(name!=null){
                //tFultbpurchasingapplyEntity.setBillnumber(name);
                stringBuffer.append(" and billnumber like '%"+name+"%'");
            }
            page.setPageNow(pageNow);
            page.setTotal(tFultbpurchasingapplyService.selectTotal(tFultbpurchasingapplyEntity));
            if(page.getPageNow()>=page.getTotalPage()){
                page.setPageNow(page.getTotalPage());
            }
            tFultbpurchasingapplyEntity.setPageUtils(page);
            tFultbpurchasingapplyEntity.setWhereSql(stringBuffer);
            List<TFultbpurchasingapplyEntity> list = tFultbpurchasingapplyService.selectForPage(tFultbpurchasingapplyEntity);
            model.addAttribute("list",list);
            model.addAttribute("radio",radio);
            model.addAttribute("page",page);
        }catch (Exception e){
            e.printStackTrace();
        }

        return "/demo/execute.jsp";

    }
}
